#pragma once


#include "RBTree.h"


namespace what
{
	template<class K, class V>
	class map
	{
	private:
		struct MapKeyOfT
		{
			const K& operator()(const std::pair<const K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, std::pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<K, std::pair<const K, V>, MapKeyOfT>::Const_Iterator const_iterator;

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator begin() const 
		{
			return _t.begin();
		}

		const_iterator end() const
		{
			return _t.end();
		}

		std::pair<iterator, bool> insert(const std::pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}

		V& operator[](const K& key)
		{
			return (_t.Insert({ key, V() }).first)->second;
		}

	private:
		RBTree<K, std::pair<const K, V>, MapKeyOfT> _t;
	};
}